package com.lx.idea.common.util;

import com.lx.idea.common.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @Author ybb
 * @Description
 * @Date 2021/9/2 16:21
 */
@Component
public class TokenUtil {

    @Autowired
    private RedisTemplate redisTemplate;
    /*
     生成token
     */
    public Map genToken(String value){
        String token = UUID.randomUUID().toString().replaceAll("-","");
        redisTemplate.opsForValue().set(token,value);
        redisTemplate.expire(token, Constant.expirTime, TimeUnit.SECONDS);
        Map map = new HashMap<>();
        map.put("token",token);
        return map;
    }

    public boolean verifyToken(String token){
        return redisTemplate.hasKey(token);
    }
}
